package cn.tedu.oa.basicInfo.service.impl;

import cn.tedu.oa.basicInfo.mapper.BasicInfoMapper;
import cn.tedu.oa.basicInfo.pojo.dto.BasicInfoQuery;
import cn.tedu.oa.basicInfo.pojo.dto.BasicInfoSaveParam;
import cn.tedu.oa.basicInfo.pojo.eneity.BasicInfo;
import cn.tedu.oa.basicInfo.pojo.vo.BasicInfoVO;
import cn.tedu.oa.basicInfo.service.BasicInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class BasicInfoServiceImpl implements BasicInfoService {
    @Autowired
    BasicInfoMapper basicInfoMapper;
    @Override
    public List<BasicInfoVO> select(BasicInfoQuery baseInfoQuery) {
        log.info("BasicInfoServiceImpl.select()");
        List<BasicInfoVO> list = basicInfoMapper.select(baseInfoQuery);
        return list;
    }

    @Override
    public void save(BasicInfoSaveParam baseInfoSaveParam) {
        log.info("BasicInfoServiceImpl.save()");
        BasicInfo basicInfo = new BasicInfo();
        BeanUtils.copyProperties(baseInfoSaveParam,basicInfo);
        if (basicInfo.getId()==null){
            log.info("新增"+basicInfo);
            basicInfo.setCreateTime(new Date());
            basicInfoMapper.insert(basicInfo);
        }else{
            log.info("修改"+basicInfo);
            basicInfo.setUpdateTime(new Date());
            basicInfoMapper.update(basicInfo);
        }

    }

    @Override
    public void delete(Integer id) {
        log.debug("删除业务，参数：{}",id);
        basicInfoMapper.delete(id);
    }
}
